package controllers.cart;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lib_model.Cart.Cart;
import lib_model.Cart.ItemCart;

/**
 * Servlet implementation class ChangeQuantity
 */
@WebServlet("/Cart/ChangeQuantityItemCart")
public class ChangeQuantityItemCart extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ChangeQuantityItemCart() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Cart cart = (Cart) request.getSession().getAttribute("Cart");
		String reason = "";
		int Id = Integer.parseInt(request.getParameter("id"));
		int Quantity = 0;
		try {
			Quantity = Integer.parseInt(request.getParameter("quantity"));
		} catch (Exception e) {
			e.printStackTrace();
			for (ItemCart ob : cart.getListCart()) {
				if (ob.id == (Id)) {
					Quantity = ob.quantity;
					break;
				}
			}

		}
		cart.ChangeQuantity(Id, Quantity);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
